package com.fjh.controller;

import com.fjh.pojo.User;
import com.fjh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    // 新增用户
    @PostMapping
    public User addUser(@RequestBody User user) {
        return userService.addUser(user);
    }

    // 根据用户名或ID查询用户
    @GetMapping("/{keyword}")
    public Optional<User> findUser(@PathVariable String keyword) {
        return userService.findUser(keyword);
    }

    // 获取所有用户
    @GetMapping
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }
}
